package com.xinmachong.springcloud.controller;

import com.xinmachong.springcloud.entities.ApiResponse;
import com.xinmachong.springcloud.entities.Payment;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.client.RestTemplate;

import javax.annotation.Resource;

/**
 * @Author meyer@HongYe
 */
@RestController
@RequestMapping("/consumer")
@Slf4j
public class OrderController {

    public static final String PAYMENT_URL = "http://127.0.0.1:8001";

    @Resource
    private RestTemplate restTemplate;


    @GetMapping("/payment/create")
    public ApiResponse<Payment> create(Payment payment) {
        return this.restTemplate.postForObject(PAYMENT_URL + "/payment/create",payment,ApiResponse.class);
    }

    @GetMapping("/payment/get/{id}")
    public ApiResponse<Payment> getPayment(@PathVariable("id") Long id) {
        return this.restTemplate.getForObject(PAYMENT_URL + "/payment/get/" + id,ApiResponse.class);
    }
}
